import store from "@/store"

export default {
	inserted(el,binding){
		// 测试环境不移除按钮
		const isDemo = process.env.VUE_APP_SHOWDEMO
		// console.log(isDemo)
		if(isDemo=="true"){
			console.log("isDemo")
			return
		}
		let permission = binding.value
		if(!permission)return
		let userPermission = store.state.permission
		let show = false
		// console.log(permission)
		if(typeof permission == "string"){
			// 字符
			// console.log("指令传入字符", permission)
			show = userPermission.includes(permission)
		}
		if(permission instanceof Array){
			// console.log("指令传入数组", permission)
			show = permission.some(item=>{
				return userPermission.includes(item)
			})
			// console.log("指令结果",show,userPermission,permission,el)
		}
		// console.log("指令结果",show,userPermission,permission,el)
		if(!show){
			el.parentNode.removeChild(el)
		}
	}
}